// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.iso;

import zombie.characters.IsoGameCharacter;
import zombie.characters.IsoPlayer;
import zombie.core.Core;
import zombie.iso.areas.IsoRoom;
import zombie.network.GameClient;
import zombie.network.GameServer;
import zombie.ui.MoodlesUI;
import zombie.ui.UIManager;

public class IsoCamera {
    public static final PlayerCamera[] cameras = new PlayerCamera[4];
    public static IsoGameCharacter CamCharacter;
    public static Vector2 FakePos;
    public static Vector2 FakePosVec;
    public static int TargetTileX;
    public static int TargetTileY;
    public static int PLAYER_OFFSET_X;
    public static int PLAYER_OFFSET_Y;
    public static final IsoCamera.FrameState frameState;

    public static void init() {
        PLAYER_OFFSET_Y = -56 / (2 / Core.TileScale);
    }

    public static void update() {
        int _int = IsoPlayer.getPlayerIndex();
        cameras[_int].update();
    }

    public static void updateAll() {
        for (int _int = 0; _int < 4; _int++) {
            IsoPlayer isoPlayer = IsoPlayer.players[_int];
            if (isoPlayer != null) {
                CamCharacter = isoPlayer;
                cameras[_int].update();
            }
        }
    }

    public static void SetCharacterToFollow(IsoGameCharacter GameChar) {
        if (!GameClient.bClient && !GameServer.bServer) {
            CamCharacter = GameChar;
            if (CamCharacter instanceof IsoPlayer
                && ((IsoPlayer)CamCharacter).isLocalPlayer()
                && UIManager.getMoodleUI((double)((IsoPlayer)CamCharacter).getPlayerNum()) != null) {
                int _int = ((IsoPlayer)CamCharacter).getPlayerNum();
                UIManager.getUI().remove(UIManager.getMoodleUI((double)_int));
                UIManager.setMoodleUI((double)_int, new MoodlesUI());
                UIManager.getMoodleUI((double)_int).setCharacter(CamCharacter);
                UIManager.getUI().add(UIManager.getMoodleUI((double)_int));
            }
        }
    }

    public static float getRightClickOffX() {
        return (float)((int)cameras[IsoPlayer.getPlayerIndex()].RightClickX);
    }

    public static float getRightClickOffY() {
        return (float)((int)cameras[IsoPlayer.getPlayerIndex()].RightClickY);
    }

    public static float getOffX() {
        return cameras[IsoPlayer.getPlayerIndex()].getOffX();
    }

    public static float getTOffX() {
        return cameras[IsoPlayer.getPlayerIndex()].getTOffX();
    }

    public static void setOffX(float aOffX) {
        cameras[IsoPlayer.getPlayerIndex()].OffX = aOffX;
    }

    public static float getOffY() {
        return cameras[IsoPlayer.getPlayerIndex()].getOffY();
    }

    public static float getTOffY() {
        return cameras[IsoPlayer.getPlayerIndex()].getTOffY();
    }

    public static void setOffY(float aOffY) {
        cameras[IsoPlayer.getPlayerIndex()].OffY = aOffY;
    }

    public static float getLastOffX() {
        return cameras[IsoPlayer.getPlayerIndex()].getLastOffX();
    }

    public static void setLastOffX(float aLastOffX) {
        cameras[IsoPlayer.getPlayerIndex()].lastOffX = aLastOffX;
    }

    public static float getLastOffY() {
        return cameras[IsoPlayer.getPlayerIndex()].getLastOffY();
    }

    public static void setLastOffY(float aLastOffY) {
        cameras[IsoPlayer.getPlayerIndex()].lastOffY = aLastOffY;
    }

    public static IsoGameCharacter getCamCharacter() {
        return CamCharacter;
    }

    public static void setCamCharacter(IsoGameCharacter aCamCharacter) {
        CamCharacter = aCamCharacter;
    }

    public static Vector2 getFakePos() {
        return FakePos;
    }

    public static void setFakePos(Vector2 aFakePos) {
        FakePos = aFakePos;
    }

    public static Vector2 getFakePosVec() {
        return FakePosVec;
    }

    public static void setFakePosVec(Vector2 aFakePosVec) {
        FakePosVec = aFakePosVec;
    }

    public static int getTargetTileX() {
        return TargetTileX;
    }

    public static void setTargetTileX(int aTargetTileX) {
        TargetTileX = aTargetTileX;
    }

    public static int getTargetTileY() {
        return TargetTileY;
    }

    public static void setTargetTileY(int aTargetTileY) {
        TargetTileY = aTargetTileY;
    }

    public static int getScreenLeft(int playerIndex) {
        return playerIndex != 1 && playerIndex != 3 ? 0 : Core.getInstance().getScreenWidth() / 2;
    }

    public static int getScreenWidth(int playerIndex) {
        return IsoPlayer.numPlayers > 1 ? Core.getInstance().getScreenWidth() / 2 : Core.getInstance().getScreenWidth();
    }

    public static int getScreenTop(int playerIndex) {
        return playerIndex != 2 && playerIndex != 3 ? 0 : Core.getInstance().getScreenHeight() / 2;
    }

    public static int getScreenHeight(int playerIndex) {
        return IsoPlayer.numPlayers > 2 ? Core.getInstance().getScreenHeight() / 2 : Core.getInstance().getScreenHeight();
    }

    public static int getOffscreenLeft(int playerIndex) {
        return playerIndex != 1 && playerIndex != 3 ? 0 : Core.getInstance().getScreenWidth() / 2;
    }

    public static int getOffscreenWidth(int playerIndex) {
        return Core.getInstance().getOffscreenWidth(playerIndex);
    }

    public static int getOffscreenTop(int playerIndex) {
        return playerIndex >= 2 ? Core.getInstance().getScreenHeight() / 2 : 0;
    }

    public static int getOffscreenHeight(int playerIndex) {
        return Core.getInstance().getOffscreenHeight(playerIndex);
    }

    static {
        for (int _int = 0; _int < cameras.length; _int++) {
            cameras[_int] = new PlayerCamera(_int);
        }

        CamCharacter = null;
        FakePos = new Vector2();
        FakePosVec = new Vector2();
        TargetTileX = 0;
        TargetTileY = 0;
        PLAYER_OFFSET_X = 0;
        PLAYER_OFFSET_Y = -56 / (2 / Core.TileScale);
        frameState = new IsoCamera.FrameState();
    }

    public static class FrameState {
        public int frameCount;
        public boolean Paused;
        public int playerIndex;
        public float CamCharacterX;
        public float CamCharacterY;
        public float CamCharacterZ;
        public IsoGameCharacter CamCharacter;
        public IsoGridSquare CamCharacterSquare;
        public IsoRoom CamCharacterRoom;
        public float OffX;
        public float OffY;
        public int OffscreenWidth;
        public int OffscreenHeight;

        public void set(int _playerIndex) {
            this.Paused = zombie.GameTime.isGamePaused();
            this.playerIndex = _playerIndex;
            this.CamCharacter = IsoPlayer.players[_playerIndex];
            this.CamCharacterX = this.CamCharacter.getX();
            this.CamCharacterY = this.CamCharacter.getY();
            this.CamCharacterZ = this.CamCharacter.getZ();
            this.CamCharacterSquare = this.CamCharacter.getCurrentSquare();
            this.CamCharacterRoom = this.CamCharacterSquare == null ? null : this.CamCharacterSquare.getRoom();
            this.OffX = IsoCamera.getOffX();
            this.OffY = IsoCamera.getOffY();
            this.OffscreenWidth = IsoCamera.getOffscreenWidth(_playerIndex);
            this.OffscreenHeight = IsoCamera.getOffscreenHeight(_playerIndex);
        }
    }
}
